clear textprogressbar; clear; clc
%%
[session, zi3543, zi3560]=MeasurementSession.TestSession.CreateSession;

%%
pc=EquipmentControl.SystemlMachine.PowerController(session, 'dev3560');
sNMRG = EquipmentControl.SystemlMachine.SimpleNMRG(session, 'dev3543');

%%
pc.performance_check();
pc.performance_plot();
pc.setTarget(1.5);
pause(5);

%%
sNMRG.initDriving('mainCurrentControlVolt', 8.948,...% V, current should be around 450.05mA
                  'nmr129freq', 258.130, 'nmr131freq', 76.530);
sNMRG.sweepNMR129('samplecount', 100, 'settling_time', 20);
sNMRG.sweepNMR131('samplecount', 100, 'settling_time', 20);

sNMRG.go2Resonance(20);

%%
sNMRG.unLock129().unLock131(); pause(10);
sNMRG.signalScope('ScopeFFTOpenLoop');
sNMRG.pollData('TimeDomainDataOpenLoop', 'duration', 60.0);
sNMRG.spectrumData('SpectrumOpenLoop', 'nAverage', 100, 'maxF', 200, 'nPoint', 8192);

%%
sNMRG.lock129().lock131(); pause(10);
sNMRG.signalScope('ScopeFFTCloseLoop');
sNMRG.pollData('TimeDomainDataCloseLoop', 'duration', 60.0);
sNMRG.spectrumData('SpectrumCloseLoop', 'nAverage', 100, 'maxF', 200, 'nPoint', 8192);
pause(5);
%%
MeasurementSession.save( session.close() );